package com.bondar.generics;

import java.util.ArrayList;
import java.util.Collection;

public class Generics {

	public static <T> void fromArrayToCollection(T[] from, Collection<T> to) {
		for (T item : from) {
			to.add(item);
		}
	}

	/**
	 * List<Fruit> fr = null; List<Apple> app = null; List<Orange> or = null;
	 * List<RedApple> rapp = null; List<Melon> mel = null;
	 */
	public static <T> void copyAll(Collection<? extends T> collection,
			Collection<T> out) {
		out.addAll(collection);
	}

	public static <E extends Comparable<Integer>> Collection<E> greaterThan(
			Collection<E> collection, Integer num) {

		Collection<E> result = new ArrayList<E>();

		for (E e : collection) {
			if (e.compareTo(num) > 0) {
				result.add(e);
			}
		}

		return result;
	}
}
